﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ConvergensDominoConnector;

namespace CDCOSDH
{
    public partial class AllActiveCases : Form
    {
        private string sdhName;
        private string viewName;

        public List<string> selectedRow = new List<string>(10);

        public AllActiveCases(string sdhName, string viewName)
        {
            InitializeComponent();

            this.sdhName = sdhName;
            this.viewName = viewName;
            this.Text = "Alle aktive sager i " + this.sdhName + " SDH";

            this.dataTableAllActiveCases.Select();
        }

        private void AllActiveCases_Load(object sender, EventArgs e)
        {
            try
            {
                this.dataTableAllActiveCases.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
                this.dataTableAllActiveCases.RowHeadersVisible = false;

                DataView dataView = new DataView(DominoConnector.Default.GetAllActiveCases(this.viewName, this.sdhName));
                this.dataTableAllActiveCases.DataSource = dataView;
                this.dataTableAllActiveCases.Columns["UNID"].Visible = false;

                this.dataTableAllActiveCases.Columns[0].Width = 98;
                this.dataTableAllActiveCases.Columns[1].Width = 500;
                this.dataTableAllActiveCases.Columns[2].Width = 133;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            List<string> selectedRow = new List<string>(10);

            foreach (DataGridViewRow row in this.dataTableAllActiveCases.SelectedRows)
            {
                selectedRow.Add(row.Cells[0].Value.ToString());
                selectedRow.Add(row.Cells[1].Value.ToString());
                selectedRow.Add(row.Cells[3].Value.ToString());
            }

            this.selectedRow.AddRange(selectedRow);
            selectedRow = null;

            this.DialogResult = DialogResult.OK;

        }

        private void dataTableAllActiveCases_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            List<string> selectedRow = new List<string>(10);
            foreach (DataGridViewRow row in this.dataTableAllActiveCases.SelectedRows)
            {
                selectedRow.Add(row.Cells[0].Value.ToString());
                selectedRow.Add(row.Cells[1].Value.ToString());
                selectedRow.Add(row.Cells[3].Value.ToString());
            }

            this.selectedRow.AddRange(selectedRow);
            selectedRow = null;

            this.DialogResult = DialogResult.OK;
        }

        private void setEnmeordContent()
        {
            if (ConvergensDominoConnector.DominoConnector.Default.GetSDHEmneOrdJaNej(this.sdhName) == "Ja")
            {
                //Regditbart Enmeord felt
            }
            else
            {

            }
        }

        private void btnCnl_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void dataTableAllActiveCases_KeyDown(object sender, KeyEventArgs e)
        {
            if (this.dataTableAllActiveCases.SelectedRows.Count == 0)
            {
                return;
            }
            if (e.KeyCode == Keys.Enter)
            {
                List<string> selectedRow = new List<string>(10);
                foreach (DataGridViewRow row in this.dataTableAllActiveCases.SelectedRows)
                {
                    selectedRow.Add(row.Cells[0].Value.ToString());
                    selectedRow.Add(row.Cells[1].Value.ToString());
                    selectedRow.Add(row.Cells[3].Value.ToString());
                }

                this.selectedRow.AddRange(selectedRow);
                selectedRow = null;
                this.DialogResult = DialogResult.OK;
            }
        }
    }
}
